#include "field_test.h"

jint accessFieldA(JNIEnv *env, jobject obj) {
    jclass clazz = env->GetObjectClass(obj);
    jfieldID fieldId = env->GetFieldID(clazz, "fieldA", "I");
    jint fieldA = env->GetIntField(obj, fieldId);
    return fieldA;
}

void writeFieldA(JNIEnv *env, jobject obj, jint value) {
    jclass clazz = env->GetObjectClass(obj);

    jfieldID fieldId = env->GetFieldID(clazz, "fieldA", "I");
    env->SetIntField(obj, fieldId, value);
}

jstring accessStaticFieldB(JNIEnv *env, jobject obj) {
    jclass clazz = env->GetObjectClass(obj);
    jfieldID fieldId = env->GetStaticFieldID(clazz, "staticFieldB", "Ljava/lang/String;");
    jstring fieldB = (jstring) env->GetStaticObjectField(clazz, fieldId);
    return fieldB;
}

void writeStaticFieldB(JNIEnv *env, jobject obj, jstring value) {
    jclass clazz = env->GetObjectClass(obj);
    jfieldID fieldId = env->GetStaticFieldID(clazz, "staticFieldB", "Ljava/lang/String;");
    env->SetStaticObjectField(clazz, fieldId, value);
}


